<?php
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);

	if (isset($ip) && isset($kid)){
		
		$ip=trim($ip);
		$kid=trim($kid);

		$servername="DRIVER={SQL Server};SERVER=10.100.160.176;DATABASE=ReportServer";
		$conn=odbc_connect($servername,'thtfmes',"Mes&thtf",SQL_CUR_USE_ODBC);
		if ($conn){
			$sql1="SELECT Name FROM Master..SysDatabases";
			$exec1=odbc_exec($conn, $sql1);
			while(odbc_fetch_row($exec1)){
				$sql="	SELECT ProductKeyID, ProductKeyState, ProductKey
							FROM ".odbc_result($exec1,"Name").".dbo.ProductKeyInfo 
						WHERE (ProductKeyID = '$kid')";
				
				$exec=odbc_exec($conn, $sql);
				while(odbc_fetch_row($exec))
				{
					print '<strong>Product Key ID: </strong><font color="red">'.odbc_result($exec,"ProductKeyID").'</font><br \>';
					print '<strong>Key State: </strong><font color="red">'.odbc_result($exec,"ProductKeyState").'</font><br \>';
					print '<strong>Product Key: </strong><font color="red">'.odbc_result($exec,"ProductKey").'</font><br \><br \>';
					odbc_close($conn);
					die("MDOS Server---".date("Y-m-d H:i:s"));
				}
			}
		}

		// finding in new server
		$servername="DRIVER={SQL Server};SERVER=$ip;DATABASE=SmartClient";
		$conn=odbc_connect($servername,'thtfmes',"Mes&thtf",SQL_CUR_USE_ODBC);
		if ($conn){
			$sql="SELECT dbo.ProductKeyInfo.ProductKeyID,dbo.ProductKey.ProductKeyState
					FROM dbo.ProductKey INNER JOIN
					dbo.ProductKeyInfo ON dbo.ProductKey.ProductKeyID = dbo.ProductKeyInfo.ProductKeyID
				WHERE (dbo.ProductKey.MSFTProductKeyID = '$kid')";
			$exec=odbc_exec($conn, $sql);
		
			if(odbc_fetch_row($exec)){
				print '<strong>Product Key ID: </strong>'.odbc_result($exec, "ProductKeyID").'<br \>';
				print '<strong>Key State: </strong><font color="red">'.odbc_result($exec, "ProductKeyState").'</font><br \>';
				odbc_close($conn);
				die("MSC Server---".date("Y-m-d H:i:s"));
			}else{
				$sql="SELECT dbo.ProductKey.ProductKeyID,dbo.ProductKey.ProductKeyState
					FROM dbo.ProductKey WHERE dbo.ProductKey.MSFTProductKeyID = '$kid'";
				$exec=odbc_exec($conn, $sql);
				if(odbc_fetch_row($exec)){
					print '<strong>Product Key ID: </strong>'.odbc_result($exec, "ProductKeyID").'<br \>';
					print '<strong>Key State: </strong><font color="red">'.odbc_result($exec, "ProductKeyState").'</font><br \>';
					odbc_close($conn);
					die("MSC Server---".date("Y-m-d H:i:s"));
				}
			}
		}
		echo "[ERROR]: No KeyID was found";
		odbc_close($conn);

	}else{
		echo "[ERROR]: information issue";
		echo "ip=$ip";
		echo "act=$act";
		echo "kid=$kid";
		echo "isNew=$isNew";
	}
?>